﻿#region File Description
// EpicLeadManager
// EpicLeadManager
// GroupsListControl.xaml.cs
#endregion

#region Using References
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using EpicLeadManager.Models;

#endregion

namespace EpicLeadManager.Views.Main
{
    /// <summary>
    ///     Interaction logic for GroupsListControl.xaml
    /// </summary>
    public partial class GroupsListControl : UserControl
    {
        private ObservableCollection<Group> _groups;

        public GroupsListControl()
        {
            InitializeComponent();

            Groups = new ObservableCollection<Group>();
        }

        public ObservableCollection<Group> Groups
        {
            get { return _groups; }
            set
            {
                _groups = value;
                RefreshGroupList(_groups);
            }
        }

        private void RefreshGroupList(ObservableCollection<Group> _groups)
        {
            GroupsListBox.ItemsSource = _groups;
        }

        private void AddGroupButton_OnClick(object sender, RoutedEventArgs e)
        {
            uint i = (uint)Groups.Count;
            Groups.Add(new Group { NumGroup = i });

            Console.WriteLine("Nouveau groupe ajouté : " + i);
        }

        private void DeleteGroupButton_OnClick(object sender, RoutedEventArgs e)
        {
            Group g = GroupsListBox.SelectedItem as Group;

            if (g != null) {
                Groups.Remove(g);
            }
        }
    }
}